<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //数组的其他循环方式
      //for是注重过程的循环方式
      //forEach是注重结果的循环方式 往往将循环的过程封装起来
      var arr = [34, 5, 32, 545, 32, 56, 78]
      for (let i = 0; i < arr.length; i++) {
        //for循环数组
        console.log(arr[i])
      }
      function newEach(fun) {
        for (let i = 0; i < this.length; i++) {
          fun(arr[i], i, this)
        }
      }
      //   newEach(arr, function (item, key, array,) {
      //     console.log(item, key, array)
      //     // break;  不支持的操作
      //   })
      Array.prototype.newEach = newEach
      arr.newEach((item, id, arr) => {
        console.log(item, id, arr)
      })

      //forEach不支持break continue操作

      var arr = [3, 34, 54, 1, 2, 54, 87]
      var arr = arr.map((val, index, array) => {
        console.log(val, index, array)
        return val
      })
      console.log(arr)
      function myMap(fn) {
        let newarr = []
        for (let i = 0; i < this.length; i++) {
          newarr[i] = fn(this[i], i, this)
        }
        return newarr
      }

      Array.prototype.myMap = myMap
      let arr1 = arr.myMap((item, index, val) => {
        return item + 10
      })
      console.log(arr1)
    </script>
  </body>
</html>
